//
// @author				mitchell
// @description		020101.html页面的JS打包文件 注意引用顺序
// @lastmodified		$2010-7 - 15$
$(document).ready(function(){
	(function($) {
		$.extend({
			add2cart: function(source_id, target_id, callback) {
			  var source = $('#' + source_id );
			  var target = $('#' + target_id );
			  var shadow = $('#' + source_id + '_shadow');//木有找到这个,但是在下边动态添加了
			  if( !shadow.attr('id') ) {
				  $('body').prepend('<div id="'+source.attr('id')+'_shadow" style="display: none; background-color: #ddd; border: solid 1px darkgray; position: static; top: 0px; z-index: 100000;">&nbsp;</div>');
			      var shadow = $('#'+source.attr('id')+'_shadow');
			  }
			  
			  if( !shadow ) {
			      alert('Cannot create the shadow div');
			  } 	
			  shadow.width(source.css('width')).height(source.css('height')).css('top', source.offset().top).css('left', source.offset().left).css('opacity', 0.5).show();
			  shadow.css('position', 'absolute');
			  
			  shadow.animate( { width: target.innerWidth(), height: target.innerHeight(), top: target.offset().top, left: target.offset().left }, { duration: 1000 } )
			    .animate( { opacity: 0 }, { duration: 300, complete: callback } );
			        
			}
		});
	})(jQuery);
	
	/*
	 *悬浮层 
	 */
	var layer = js_context.layer;
	if($("#mask").is(":visible")){
		$('#mask').click(function(event){
		   if(!$(event.target).hasClass('yindao')){
			   if(!confirm("是否退出引导向导？")){
				   return false;
			   }
			   var type = $(".layer_"+layer).attr("type");
			   var url =js_context.base_url+"ajax/account/pic_layer";
			   $.get(url,{"type" : type}, function(result){
					if(result.success == false){
						alert('通讯失败');
						return false;
					}
					$(".out_wk,.layer_"+layer+", .layer1_"+layer).hide();
					if($(".layer_"+layer).attr('typeid') == 'input_s'){
						$(".address").focus();
					}
//					if(result.message.value){
//						layer = result.data;
//						$(".layer_"+layer+", .layer1_"+layer).show();
//						$("."+layer).click(function(event){
//							event.preventDefault();
//							var type = $(".layer_"+layer).attr("type");
//							$.get(url,{"type" : type}, function(result){
//								if(result.success == false){
//									alert('通讯失败');
//									return false;
//								}
//								$(".layer_"+layer+", .layer1_"+layer).hide();
//							 },"json");
//						});
//					}
					
				 },"json");
		   }
		});
	}
	$("."+layer).click(function(event){
		event.preventDefault();
		var _this = this;
		var type = $(".layer_"+layer).attr("type");
		var url =js_context.base_url+"ajax/account/pic_layer";
		
		$.get(url,{"type" : type}, function(result){
			if(result.success == false){
				alert('通讯失败');
				return false;
			}
			$(".out_wk,.layer_"+layer+", .layer1_"+layer).hide();
			if($(".layer_"+layer).attr('typeid') == 'input_s'){
				$(".address").focus();
			}
			if(result.message.value){
				layer = result.data;
				$(".layer_"+layer+", .layer1_"+layer).show();
				$("."+layer).click(function(event){
					event.preventDefault();
					var type = $(".layer_"+layer).attr("type");
					$.get(url,{"type" : type}, function(result){
						if(result.success == false){
							alert('通讯失败');
							return false;
						}
						$(".layer_"+layer+", .layer1_"+layer).hide();
					 },"json");
				});
			}
			
		 },"json");
	});

	$(document).keyup(function(e){
		if(e.which == 27){
			var temp= $(".layer_"+layer).is(":visible");//是否可见
			if(!temp){ 
				return false;
			}
			var type = $('.close_1');
			var key = false;
			type.each(function(i){
			   if($(this).is(":visible")){
				   type = $(this).attr("type");
				}
			});
			
			var url =js_context.base_url+"ajax/account/pic_layer";
			$.get(url,{"type" : type}, function(result){
				if(result.success == false){
					alert('通讯失败');
					return false;
				}
				$('.out_wk,.layer_'+layer+", .layer1_"+layer).hide();
				var data = result.data;
				if(result.message.value ){
					layer = result.data;
					$(".layer_"+layer+", .layer1_"+layer).show();
					$("."+layer).click(function(event){
						event.preventDefault();
						var type = $(".layer_"+layer).attr("type");
						$.get(url,{"type" : type}, function(result){
							if(result.success == false){
								alert('通讯失败');
								return false;
							}
							$(".layer_"+layer+", .layer1_"+layer).hide();
						 },"json");
					});
					
				}
			 },"json");
		}
	});
	
	$(".right_div").click(function(event){
		event.preventDefault();
		var div = $(this).attr("type");
		var typeid = $(this).attr("typeid");
		var num = $(this).attr("num");
		$("."+div).slideToggle(800);
		
		if(typeid=="xs"){
			$(".xs_"+num).hide();
			$(".yc_"+num).show();
			return false;
		}
		$(".yc_"+num).hide();
		$(".xs_"+num).show();
	});

	//header 顶部导航栏展开收起
	$(".header-tr-nav").mouseover(function(event){
		var _this = this;
		$(".usercontact_list,.h_zk").show();
		$('.h_yc').hide();
		$(_this).mouseleave(function(){
			$(".usercontact_list").hide();
			$('.h_zk').hide();
			$('.h_yc').show();
		});
	});
	$(".header-tr-cart").mouseover(function(event){
		event.preventDefault();
		var _this = this;
		$(".header-tr-carts").show();
		$(".header-tr-cartk").css("background","url("+js_context.base_url+"res/images/header-carth.gif)");
		$(_this).mouseleave(function(){
			$(".header-tr-carts").hide();
		});
	});
	$(".header-tr-carts").mouseleave(function(){
		$(".header-tr-cartk").css("background","url("+js_context.base_url+"res/images/header-cart.gif)");
	});
	
	
	$(".shopcar_other").click(function(){//外卖展开隐藏
		$(".shopcar_other").hide();
		var type = $(this).attr("type");
		$(".shopcar_"+type).show();
		$("#cart").slideToggle(1000);
	});
	
	var shopcarnum = js_context.shopcarnum;
	//点击菜品添加进购物车
	$(".jiagou1").click(function(event){
		event.preventDefault();
		
		var re = /^[1-9]+[0-9]*]*$/;     
		var scount = $("#count").val();
		if (scount!=undefined && !re.test(scount)){
	    	 alert("输入有误请重新输入！");
	    	 return false;
	    }
		//shop_order_big为右侧购物车悬浮框 cart_shrink为悬浮框标题
		$(".cartc,.shop_order_big,.cart_shrink").show();
		shopcarnum = true;
		var _this = this;
		var fid = $(this).attr('f_fid');
		var sid = $(this).attr('f_sid');
		var s_name = $(this).attr('f_store');
		var s_mincost = $(this).attr('s_mincost');
		var servecost = $(this).attr('servecost');//服务费
		var count = $("#count").val();//count在下边交互后直接在购物车添加商品的同时写进网页中
		//后台添加到购物车的网址
		var url = js_context.base_url+"ajax/shopping/add";
		//购物车共header_num件
		var header_num = $(".header_shopcar_num").html();
		//http://www.waimai.com/ajax/shopping/add?sid=2069&fid=316616&s_name=%E6%B0%B8%E5%92%8C%E5%A4%A7%E7%8E%8B(%E5%8F%8C%E6%A6%86%E6%A0%91%E5%BA%97)&servecost=0
		$.get(url,{'count' : count,'sid' : sid, 'fid' : fid,'s_name' : s_name,'servecost' : servecost}, function(result){
			//result
			/*{
			    "message": [//更新右侧悬浮窗,只有当前店铺购物车信息
			        {
			            "cartid": "87921",
			            "fid": "316609",
			            "uid": "0",
			            "sid": "2069",
			            "f_name": "大王卤肉饭",
			            "price": "15.00",
			            "count": "1",
			            "s_name": "永和大王(双榆树店)",
			            "servecost": "0"
			        },
			        {
			            "cartid": "87922",
			            "fid": "316616",
			            "uid": "0",
			            "sid": "2069",
			            "f_name": "开胃酸菜",
			            "price": "3.00",
			            "count": "1",
			            "s_name": "永和大王(双榆树店)",
			            "servecost": "0"
			        }
			    ],
			    "shopcar": [//更新导航栏购物车,可有多家店信息
			        {
			            "cartid": "87921",
			            "fid": "316609",
			            "uid": "0",
			            "sid": "2069",
			            "f_name": "大王卤肉饭",
			            "price": "15.00",
			            "count": "1",
			            "s_name": "永和大王(双榆树店)",
			            "servecost": "0"
			        },
			        {
			            "cartid": "87922",
			            "fid": "316616",
			            "uid": "0",
			            "sid": "2069",
			            "f_name": "开胃酸菜",
			            "price": "3.00",
			            "count": "1",
			            "s_name": "永和大王(双榆树店)",
			            "servecost": "0"
			        }
			    ],
			    "arr": [//没有使用过这个,不知道干嘛的
			        [
			            {
			                "cartid": "87921",
			                "fid": "316609",
			                "uid": "0",
			                "sid": "2069",
			                "f_name": "大王卤肉饭",
			                "price": "15.00",
			                "count": "1",
			                "s_name": "永和大王(双榆树店)",
			                "servecost": "0",
			                "mincost": "30"
			            },
			            {
			                "cartid": "87922",
			                "fid": "316616",
			                "uid": "0",
			                "sid": "2069",
			                "f_name": "开胃酸菜",
			                "price": "3.00",
			                "count": "1",
			                "s_name": "永和大王(双榆树店)",
			                "servecost": "0",
			                "mincost": "30"
			            }
			        ]
			    ],
			    "error": false,
			    "num": 1,
			    "success": true
			}*/

			if(result.success == false){
				alert('通讯失败');
				return false;
			}
			var data = result.message;
			var shopcar = result.shopcar;//购物车
			
			if(!data){
				alert('添加失败');
				return false;
			}
			//目前num一直为1
			if(result.num > 1){
				$(".shopcar_title").html("点击购物车查看餐品");
				$(".shopcar_title").attr('href',js_context.base_url+'shopcar/order');
			}else{
				$(".shopcar_title").html("欢迎光临外卖网");
				$(".shopcar_title").attr('href','javascript:void(0)');
			}
			
			//$(".y_shop_"+fid).show().fadeOut(4000);
			$('.cart-xiadan').hide();//这个提示也没有显示
			$.add2cart( 'fid_'+fid, 'shopcar_box');//'fid_'xxx是某个菜品的方框div,点击之后出来个阴影缩放特效加进购物车里边
			var html = "";
			var priceall = 0;
			//把resule.message返回的信息添加到悬浮购物车中
			for(var i=0;i<data.length;i++){
				if(fid == data[i].fid){
					html +='<div style="display:none" class="cart-fact2 foods_'+data[i].fid+' shop_'+data[i].fid+'">';//修改出红框class效果
				}else{
					html +='<div class="cart-fact shop_'+data[i].fid+'">';
				}
				html +='<div class="cart-fact-name"><a href="'+js_context.base_url+'food/'+data[i].fid+'">'+data[i].f_name.substr(0,9)+'.</a></div>';
				html +='<div class="cart-fact-amount">';
				html +='<a href="javascript:void(0)" class="cart-fact-amountl updatenum" count="-1" fid="'+data[i].fid+'" sid="'+data[i].sid+'" cartid="'+data[i].cartid+'"><img src="'+js_context.base_url+'res/images/-.gif" /></a>';
				html +='<span>'+data[i].count+'</span>';
				html +='<a href="javascript:coid(0)" class="cart-fact-amountr updatenum" count="1" fid="'+data[i].fid+'" sid="'+data[i].sid+'"  cartid="'+data[i].cartid+'"><img src="'+js_context.base_url+'res/images/+.gif" /></a></div>';
				html +='<div class="cart-fact-price">'+data[i].price+'</div>';
				html +='<div class="cart-fact-del"><a href="javascript:void(0)" class="shopcar_del del_cartid_'+data[i].cartid+'" cartid="'+data[i].cartid+'" sid="'+data[i].sid+'" fid="'+data[i].fid+'"><img src="'+js_context.base_url+'res/images/del.gif" /></a></div>';
				html +='</div>';
				priceall = priceall + data[i].price*data[i].count;//计算总价格
			}
			$(".cart-ifact").html(html);//把新的html列表覆盖到悬浮框中
			
			//添加到导航购物车中
			var headerhtml="";
			for(var i=0;i<shopcar.length;i++){
				headerhtml += '<div class="header-item shop_'+shopcar[i].fid+'">';
				headerhtml += '<a href="'+js_context.base_url+'food/'+shopcar[i].fid+'" class="header-ia">'+shopcar[i].f_name.substr(0,7)+'</a>';
				headerhtml += '<font><label>'+shopcar[i].price+'</label></font>';
				headerhtml += '<a href="javascript:void(0)" class="header_shopcar_del del_cartid_'+shopcar[i].cartid+'" cartid="'+shopcar[i].cartid+'" fid="'+shopcar[i].fid+'">删除</a>';
				headerhtml += '</div>';
			}
			
			$("#ca").html(headerhtml);//ca为导航栏购物车
			$(".header_shopcar_num").html(shopcar.length);//导航栏购物车数量
			if($('.shopcar_list').html()){
				$('.word').html("最近加入的菜品");//如果为0就是您的购物车没有任何商品
			}
			
			var rex=/\d+[.]\d{1}/g;
			var allprice = 0;
			if(!rex.test(priceall)){//格式化priceall总价
				allprice = priceall+".00";
			}else{
				allprice = priceall+"0"; 
			}
			$(".all_price").html("总计：￥"+allprice+"元");
			
			function del(){
				$(".foods_"+fid).attr("class","cart-fact shop_"+fid);//在循环中改变cart-fact shop_即购物车悬浮车的每行的样式,点击添加的时候先是红框过1秒才变正常的
			}
			$('.shop_'+fid).fadeIn(1000, del );
			//shopcar edit food number.
			setTimeout(function(){$("#fid_"+fid+"_shadow").remove()},2000); //把效果阴影都删了
			$(".updatenum,.header_updatenum").click(function(event){//+ -按钮点击事件,<a>按钮还自带sid 和fid的
				event.preventDefault();
				var count_this = this;
				var sid = $(count_this).attr('sid');
				var fid = $(count_this).attr('fid');
				var cartid = $(count_this).attr('cartid');
				var count_dom = $(count_this).parent().find('span');//数量节点
				var input_dom = $(count_this).parent().find('span').html();//数量值
				
				if(input_dom== '0'){
					return false;
				}
				var count = $(count_this).attr('count');
				if(input_dom == '1' && count == '-1'){//如果只有一个点了-就是删除商品啦
					if(confirm('将删除该商品')){
						//删除请求
						var url = js_context.base_url+"ajax/shopping/delete";
						$.get(url,{'fid' : fid,'cartid' : cartid,'sid' : sid}, function(result){
							/*{
							    "message": [
							        {
							            "cartid": "87972",
							            "fid": "316616",
							            "uid": "0",
							            "sid": "2069",
							            "f_name": "5f0080c3917883dc",
							            "price": "3.00",
							            "count": "2",
							            "s_name": "6c38548c5927738b(53cc698668115e97)",
							            "servecost": "0"
							        }
							    ],
							    "shopcar": [
							        {
							            "cartid": "87968",
							            "fid": "300001",
							            "uid": "0",
							            "sid": "2770",
							            "f_name": "70ed8c466d46 (751c)",
							            "price": "5.50",
							            "count": "1",
							            "s_name": "771f529f592b(592951436e2f5e97)",
							            "servecost": "55143"
							        },
							        {
							            "cartid": "87969",
							            "fid": "300002",
							            "uid": "0",
							            "sid": "2770",
							            "f_name": "51bb8c466d46 (751c)",
							            "price": "6.00",
							            "count": "1",
							            "s_name": "771f529f592b(592951436e2f5e97)",
							            "servecost": "55143"
							        },
							        {
							            "cartid": "87972",
							            "fid": "316616",
							            "uid": "0",
							            "sid": "2069",
							            "f_name": "5f0080c3917883dc",
							            "price": "3.00",
							            "count": "2",
							            "s_name": "6c38548c5927738b(53cc698668115e97)",
							            "servecost": "0"
							        }
							    ],
							    "success": true
							}*/
							$('.shop_'+fid).remove();
							if(result.success == false){
								alert('通讯失败');
								return false;
							}
							var data = result.message;
							var shopcar = result.shopcar;
							if(!data){
								alert('删除失败');
								return false;
							}
							$('.shop_'+fid).remove();//删除对应商品列表..应该导航栏和悬浮的都删了
							if(!$('.cart-ifact').html()){//如果列表没有菜品了
								$('.cart-xiadan').show();
								shopcarnum = false;
								$(".cartc,.shop_order_big").hide();//隐藏购物车
							}
							//header修改导航栏
							$('.header_shopcar_num').html(shopcar.length);
							if($('.shopcar_list').html()==false){
								$('.word').html("您的购物车没有任何商品");
							}
							//update price
							var priceall = 0;
							for(var i=0;i<data.length;i++){
								priceall = priceall + data[i].price*data[i].count;
							}
							
							var rex=/\d+[.]\d{1}/g;
							var allprice = 0;
							if(!rex.test(priceall)){
								allprice = priceall+".00";
							}else{
								allprice = priceall+"0"; 
							}
							$(".all_price").html("总计：￥"+allprice+"元");
						},"json");
					}
					return false;//删完就return false了就不执行下边的了
				}
				//如果没有删掉节点就执行这个同步服务器
				$.get(js_context.base_url+"ajax/shopping/add",{'sid':sid,'fid' : $(count_this).attr('fid'),'cartid' : $(count_this).attr('cartid'),'count':count}, function(result){
					if(result.success == false){
						alert('通讯失败');
						return false;
					}
					var data = result.message;
					if(!data){
						alert('操作失败');
						return false;
					}
					//update price
					var priceall = 0;
					for(var i=0;i<data.length;i++){
						priceall = priceall + data[i].price*data[i].count;
					}
					
					var rex=/\d+[.]\d{1}/g;
					var allprice = 0;
					if(!rex.test(priceall)){
						allprice = priceall+".00";
					}else{
						allprice = priceall+"0"; 
					}
					$(".all_price").html("总计：￥"+allprice+"元");
					count_dom.html((Number(count)+Number(input_dom)));//改变点击按钮这行的数量
				},"json");
			});
			//delete
			$(".shopcar_del, .header_shopcar_del").click(function(event){//删除的X
				event.preventDefault();
				var fid = $(this).attr('fid');
				var sid = $(this).attr('sid');
				var cartid = $(this).attr('cartid');
				var url = js_context.base_url+"ajax/shopping/delete";
				$.get(url,{'cartid' : cartid,'sid' : sid}, function(result){

					$('.shop_'+fid).remove();
					if(result.success == false){
						alert('通讯失败');
						return false;
					}
					var data = result.message;
					var shopcar = result.shopcar;
					
					if(!data){
						alert('删除失败');
						return false;
					}
					$('.shop_'+fid).remove();
					if($('.cart-ifact').html()==false){
						$('.cart-xiadan').show();
						shopcarnum = false;
						$(".cartc,.shop_order_big").hide();
					}
					$('.header_shopcar_num').html(shopcar.length);
					if($('.shopcar_list').html()==false){
						$('.word').html("您的购物车没有任何商品");
					}
					
					//update price
					var priceall = 0;
					for(var i=0;i<data.length;i++){
						priceall = priceall + data[i].price*data[i].count;
					}
					
					var rex=/\d+[.]\d{1}/g;
					var allprice = 0;
					if(!rex.test(priceall)){
						allprice = priceall+".00";
					}else{
						allprice = priceall+"0"; 
					}
					$(".all_price").html("总计：￥"+allprice+"元");
				},"json");
			});
			
		},"json");
	});
	
	//shopcar edit food number.    我不知道下边为什么会有和上边重复的不要问我...反正不用看了
	$(".updatenum").click(function(event){
		event.preventDefault();
		var fid = $(this).attr('fid');
		var sid = $(this).attr('sid');
		var cartid = $(this).attr('cartid');
		var count_dom = $(this).parent().find('span');
		var input_dom = $(this).parent().find('span').html();
		if(input_dom== '0'){
			return false;
		}
		var count = $(this).attr('count');
		if(input_dom == '1' && count == '-1'){
			if(confirm('将删除该商品')){
				var url = js_context.base_url+"ajax/shopping/delete";
				$.get(url,{'fid' : fid,'cartid' : cartid,'sid' : sid}, function(result){
					$('.shop_'+fid).remove();
					if(result.success == false){
						alert('通讯失败');
						return false;
					}
					var data = result.message;
					var shopcar = result.shopcar;
					if(!data){
						alert('删除失败');
						return false;
					}
					$('.shop_'+fid).remove();
					if(!$.trim($('.cart-ifact').html())){
						$('.cart-xiadan').show();
						shopcarnum = false;
						$(".cartc,.shop_order_big").hide();
					}
					//header
					$('.header_shopcar_num').html(shopcar.length);
					if($('.shopcar_list').html()==false){
						$('.word').html("您的购物车没有任何商品");
					}
					//update price
					var priceall = 0;
					for(var i=0;i<data.length;i++){
						priceall = priceall + data[i].price*data[i].count;
					}
					
					var rex=/\d+[.]\d{1}/g;
					var allprice = 0;
					if(!rex.test(priceall)){
						allprice = priceall+".00";
					}else{
						allprice = priceall+"0"; 
					}
					$(".all_price").html("总计：￥"+allprice+"元");
				},"json");
			}
			return false;
		}
		$.get(js_context.base_url+"ajax/shopping/add",{'fid' : $(this).attr('fid'),'sid':sid ,'count':count}, function(result){
			if(result.success == false){
				alert('通讯失败');
				return false;
			}
			var data = result.message;
			if(!data){
				alert('操作失败');
				return false;
			}
			//update price
			var priceall = 0;
			for(var i=0;i<data.length;i++){
				priceall = priceall + data[i].price*data[i].count;
			}
			
			var rex=/\d+[.]\d{1}/g;
			var allprice = 0;
			if(!rex.test(priceall)){
				allprice = priceall+".00";
			}else{
				allprice = priceall+"0"; 
			}
			
			$(".all_price").html("总计：￥"+allprice+"元");
			count_dom.html((Number(count)+Number(input_dom)));
		},"json");
	});
	//shopcar del
	$(".shopcar_del, .header_shopcar_del").click(function(event){
		event.preventDefault();
		var fid = $(this).attr('fid');
		var sid = $(this).attr('sid');
		var cartid = $(this).attr('cartid');
		var url = js_context.base_url+"ajax/shopping/delete";
		$.get(url,{'cartid' : cartid,'sid' : sid}, function(result){
			$('.shop_'+fid).remove();
			if(result.success == false){
				alert('通讯失败');
				return false;
			}
			var data = result.message;
			if(!data){
				alert('删除失败');
				return false;
			}
			if($('.cart-ifact').html()==false){
				$('.cart-xiadan').show();
				shopcarnum = false;
				$(".cartc,.shop_order_big").hide();
			}
			//header
			$('.shop_'+fid).remove();
			$('.foodcartid_'+fid).remove();
			if($.trim($("#arr_"+sid).html())==''){
				$(".shopcar_sid_"+sid).remove();
			}
			if($(".list_div ").length == 0){
				$('.word_shopcar').html("您的购物车没有任何商品");
				$('.word_shopcar').attr('href',js_context.base_url);
				$(".wrong_shop").show();
			}
			if($('.shopcar_list').html()==false){
				$('.word').html("您的购物车没有任何商品");
				$('.header_shopcar_num').html("0");
			}
			$('.header_shopcar_num').html(result.shopcar.length);
			if($('.shopcar_list').html()==false){
				$('.word').html("您的购物车没有任何商品");
			}
			//update price
			var priceall = 0;
			for(var i=0;i<data.length;i++){
				priceall = priceall + data[i].price*data[i].count;
			}
			
			var rex=/\d+[.]\d{1}/g;
			var allprice = 0;
			if(!rex.test(priceall)){
				allprice = priceall+".00";
			}else{
				allprice = priceall+"0"; 
			}
			$(".all_price").html("总计：￥"+allprice+"元");
		},"json");
	});
	
	var isIE=!!window.ActiveXObject;//这对ie6优化.....
	var isIE6 = isIE&&!window.XMLHttpRequest;
	if(isIE6){
		return false;
	}
	var shopcar_box = $("#shopcar_box");
	trip_shopcar = function() {
        var st = $(document).scrollTop();
        
        //$('.menu_ts').animate({ "margin-top":st },300);
        
        var width = $(window).width()/2 + 171;
        if(st > 195){
        	$("#huidingbu,.ret_top,.ret_top1").show();
        	if(shopcarnum == 0){
        		$(".shop_order_big").attr("class","cartc").hide();
        	}else{
        		$(".shop_order_big").attr("class","cartc").show();
        	}
			shopcar_box.css("left", width);
        }else{
        	if(shopcarnum == 0){
        		$(".cartc").attr("class","shop_order_big").hide();
        	}else{
        		$(".cartc").attr("class","shop_order_big").show();
        	}
        	$("#huidingbu,.ret_top,.ret_top1").hide();
        }
    };
    $(window).bind("scroll", trip_shopcar);
    
	//all_somo search input
	var somoid = js_context.somoid;
	var somoname = js_context.somoname;
	var keyword_store = js_context.keyword_store;
	var keyword_somo = js_context.keyword_somo;
	var index_s = js_context.index_s;
	if(somoid!=null || keyword_store!=null){
		$(document).scrollTop(170);
	}
	$(".somo_input").blur(function(event){
		var value = $.trim($(".somo_input").val());
		if(!value){
			if(somoname){
				$(".somo_input").val(somoname);
				return false;
			}
			if(keyword_somo==null){
				$(".somo_input").val('请输入您所在的大厦');
				return false;
			}
			$(".somo_input").val(keyword_somo);
		}
	});
	
	$(".index_s_input").blur(function(event){
		var value = $.trim($(this).val());
		if(!value){
			$(this).val(index_s);
		}
	});
	
	$(".all_somo_button").click(function(event){
		//event.preventDefault();
		var somo_q = $.trim($(".somo_input").val());
		var somo_url = $(".somo_input").attr("url");
		$(".somo_page").val(1);
		var page = $(".somo_page").val();
		var store_q = $.trim($(".store_input").val());
		var url = js_context.base_url+"ajax/search/s_like_somo";
		if(!store_q||store_q=='请输入餐厅名称'){
			event.preventDefault();
			if(!somo_q || somo_q == "请输入您所在的大厦"){
				alert("请输入写字楼名称");
				return false;
			}
			$("#form_url").attr("action",somo_url);
			$.get(url,{'somo_q':somo_q},function(result){
				if(result.success == false){
					alert('通讯失败');
					return false;
				}
				if(result.somodata){
					self.location = js_context.base_url+'search?somoid='+result.somodata.somoid;
					return false;
				}
				var data = result.message;
				var html = '';
				if(!data){
					html += '<div class="wrong-wu">没有找到相关写字楼，请你尝试<a href="'+js_context.base_url+'">地址搜索</a>或<a href="'+js_context.base_url+'search/map">地图搜索</a></div>';
					$("#wrong-upload").hide();
				}else{
					html += '<div class="wrong">';
					for(var i=0;i<data.length;i++){
						html += '<a href="'+js_context.base_url+'search?somoid='+data[i].somoid+'" title="'+data[i].name+'">'+data[i].name.substring(0,8).replace(somo_q,'<B style="color:red">'+somo_q+'</B>')+'</a>';
					}
						html += '</div><div style="clear:both;"></div>';

					if(result.count < 24){
						$("#wrong-upload").hide();
					}else{
						$("#wrong-upload").show();
					}
				}
				$(".somoarr_list").html(html);
				$("#wrong").show();
			},"json");
		}else{
			
			
		}
	});

	$(".somo_Load").click(function(event){
		var somo_q = $.trim($(".somo_input").val());
		$(".somo_page").val(Number($(".somo_page").val())+1);
		var page = $(".somo_page").val();
		var url = js_context.base_url+"ajax/search/s_like_somo";
		$.get(url,{'somo_q':somo_q,'page':page},function(result){
			if(result.success == false){
				alert('通讯失败');
				return false;
			}
			var data = result.message;
			if(!data){
				alert('查询失败');
				return false;
			}
			var html = '';
			for(var i=0;i<data.length;i++){
				html += '<div class="wrong"><a href="'+js_context.base_url+'search?somoid='+data[i].somoid+'" title="'+data[i].name+'">'+data[i].name.substring(0,8).replace(somo_q,'<B style="color:red">'+somo_q+'</B>')+'</a></div>';
			}
				html += '<div style="clear:both;"></div>';

			$(".somoarr_list").append(html);
			$("#wrong").show();
			$(".somo_page").val(Number(page));
		},"json");
	});
	
	$(".store_input").change(function(event){
		//event.preventDefault();
		var somo_q = $.trim($(".somo_input").val());
		var somo_url = $(".somo_input").attr("url");
		var store_q = $.trim($(".store_input").val());
		var store_url = $(".store_input").attr("url");
		var url = js_context.base_url+"ajax/search/s_like_somo"
		if(store_q!=""){
			$("#form_url").attr("action",store_url);
			return false;
		}
	});
	
	//商铺首页 菜单列表
	$(".get_food").mouseover(function(){
		var fid = $(this).attr("fid");
		$(".f_"+fid).show();
		$(this).mouseleave(function(){
			$(".f_"+fid).hide();
		});
	});
	
	//招商  入驻 商铺入驻
	var courier = js_context.courier;
	$('.submit').click(function(event){
		event.preventDefault();
		var firmname = $.trim($('.firmname').val());
		var tel = $.trim($('.s_tel').val());
		var storename = $.trim($('.storename').val());
		var contact = $.trim($('.s_contact').val());
		var address = $.trim($('.s_address').val());
		
		if(tel==""||firmname==""){
			event.preventDefault();
			alert("姓名和联系方式不能为空");
			return false;
		}
		if(courier != 'courier'){
			if(contact==""){
				event.preventDefault();
				alert("订餐电话不能为空");
				return false;
			}
			if(address==""){
				event.preventDefault();
				alert("商铺地址不能为空");
				return false;
			}
			if(storename=="" ){
				alert("商铺名称不能为空");
				return false;
			}
		}
		

		var username = $.trim($("#username").val()); 
		var password = $.trim($("#password").val());
		var firmname = $("#firmname").val();
		var name = $("#storename").val();
		var s_tel = $("#s_tel").val();//负责人电话
		var email = document.getElementById("email").value;
		var contact = $("#contact").val();//订餐电话
		var address = $("#address").val();//店铺地址
		var area = $("#area").val();//店铺地址
		var foodtype = $("#foodtype").val();
		var info = $("#info").val();//餐饮信息
		var mincost = $("#mincost").val();
		var servecost = $("#servecost").val();
		var selltime = $("#selltime").val();
		var endtime = $("#selltime1").val();
		var latitude = $("#lat").val();
		var longitude = $("#lng").val();
		//有几项不是*的没填
		var url =js_context.base_url+"user/shopreg";
		$.post(url,{"pname":username,"password":password,'mail':email,'name':firmname,'storeName':name,
					'tel':s_tel,'otel':contact,'address':address,'area':area
					,'foodtype':foodtype,'info':info,'mincost':mincost,'deliveryscost':servecost
					,'servicetime':selltime+'-'+endtime,'latitude':latitude,'longitude':longitude}, function(r){//""里的字段对应映射类的成员名
						var obj = r;
						if (obj.success) {
							window.location.href = js_context.base_url;
						}
						$.messager.show({
							title : '提示',
							msg : obj.msg
						});
			},"json");
		
	});
	
	//服务中心
	$("#ask_c").focus(function(event){
		var _this = this;
		$(_this).val("");
	});
	$("#ask_c").blur(function(event){
		if($.trim($(this).val())==""){
			$(this).val("对我们有意见和建议？请给我们留言吧！");
		}
	});
	
	$(".ask_tj").click(function(event){
		event.preventDefault();
		var content = $('#ask_c').val();
		var typeid = $(this).attr('typeid');
		var type = $(this).attr('types');
		if(content == ''|| content =='对我们有意见和建议？请给我们留言吧！'){
			alert('请输入您的问题！')
			return false;
		}
		if(content.length < 6){
			alert('请您仔细阐述您的问题！')
			return false;
		}
		
		$(this).attr("disabled", "true");
		var _this = this;
		$(".input_loading").show();
		var url = $('.form_ask').attr('action');
		$.get(url,{'content':content,'typeid':typeid,'type':type}, function(result){
			$(_this).attr("disabled", "");
			$(".input_loading").hide();
			if(result.success == false){
				alert('通讯失败');
				return false;
			}
			var data = result.message;
			if(!data){
				alert('提交失败');
				return false;
			}
			if(data.error == 'notlogin'){
				alert('请先登录!');
				return false;
			}
			if(data.error=='insertfalse'){
				alert('提交问题失败,页面将马上刷新!');
				self.location.reload;
				return false;
			}
			if(data.error=='time'){
				alert('请您半小时后在提交');
				return false;
			}
			alert("提交成功，感谢您的参与");
			$('#ask_c').attr('value','');
		},"json");
	});
	
	//visited
	  var data = js_context.data;
	  if(data){
		  $(".guidance").mouseover(function(){
			  var _this = this;
			  $(_this).find("div:eq(0)").attr("class","h-cha"); 
		  });
		  
		  $(".guidance").mouseleave(function(){
			  var _this = this;
			  $(_this).find("div:eq(0)").attr("class",""); 
		  });
	  }
	  $(".del").click(function(event){
			event.preventDefault();
			var _this = this;
			var ustatid = $(_this).attr("ustatid");
			var url = $(_this).attr("url");
			$('.loading_'+ustatid).show();
			$('.store_'+ustatid).fadeOut();
			$.get(url,{ "ustatid" : ustatid}, function(result){
				$('.loading_'+ustatid).hide();
				if(result.success == false){
					alert('通讯失败');
					return false;
				}
				var data = result.message;
				if(!data){
					alert('删除失败');
					return false;
				}
				if(data=="notlogin"){
					alert('请先登录');
					return false;
				}
				if(data=="error"){
					alert('删除失败');
					return false;
				}
				$('.store_'+ustatid).hide();
			},"json");
		});
	 //footer
	 $(".help_links").click(function(){
		 var num = $(this).attr("num"); 
		 if(num == 1){window.open(js_context.base_url+'help/consultation');}
		 if(num == 2){window.open(js_context.base_url+'help/about_us');}
		 if(num == 3){window.open(js_context.base_url+'help/process');}
		 if(num == 4){window.open('/news.waimai.com');}
		 if(num == 5){window.open(js_context.base_url+'help/league');}
		 if(num == 6){window.open(js_context.base_url+'help/courier');}
		 if(num == 7){window.open(js_context.base_url+'help/question');}
	 });
	 
});
